/*
 * @Author: yangzonglong
 * @Date: 2021-05-11 15:26:13
 * @version: v1.0.0
 * @Descripttion:
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-11-29 17:01:22
 * @Auditor:
 */
import React, { useRef, forwardRef, useCallback } from 'react';
import Table from './Table';
import { ControlRefProps } from '../../interface'
import { Modal } from 'antd'

interface IProps {
  visible: boolean;
  onOK: (res: any[]) => void;
  onCancel: () => void;
  tableProps: any;
  formItemProps: any;
  scriptsChangeData: any;
  sendData: any
}

const ModalForm = ({ visible, onOK, onCancel, tableProps, formItemProps, scriptsChangeData, sendData }: IProps) => {

  const tableRef = useRef<ControlRefProps | any>(null);

  const _onOK = useCallback(async () => {
    const res = tableRef?.current?.getData()
    res?.length && onOK(res)
  }, [onOK])


  return (
    <Modal title={'默认值'} destroyOnClose onOk={_onOK} visible={visible} onCancel={onCancel} width={1200} bodyStyle={{ height: '70vh', overflow: 'auto' }}>
      <Table inEditInitVal ref={tableRef} tableProps={tableProps} formItemProps={formItemProps} scriptsChangeData={scriptsChangeData} sendData={sendData} />
    </Modal>
  );
};

export default forwardRef(ModalForm);
